package com.blockmeta.bbs.immodule.widget;

import android.content.Context;
import android.content.DialogInterface;
import android.view.View;

import com.blockmeta.bbs.baselibrary.utils.ToastUtil;
import com.blockmeta.bbs.baselibrary.utils.loading.ProgressBarUtil;
import com.blockmeta.bbs.businesslibrary.net.pojo.BaseImResponse;
import com.blockmeta.bbs.businesslibrary.net.retrofit.RetrofitFactory;
import com.blockmeta.bbs.businesslibrary.net.rxjava.CommonSubscriber;
import com.blockmeta.bbs.businesslibrary.net.rxjava.RxUtil;
import com.blockmeta.bbs.businesslibrary.util.AccountHelper;
import com.blockmeta.bbs.immodule.R;
import com.blockmeta.bbs.immodule.net.api.JoinCircleApi;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;


public class IMAddCircleMsg extends IMSysPopup
{

	long mCircleId;

	public IMAddCircleMsg(Context pContext, long circleId)
	{
		super(pContext);
		mCircleId = circleId;
	}

	@Override
	protected void onDismiss(DialogInterface dialog)
	{

	}

	@Override
	protected void initializeView(View pView)
	{
		m_tvTitle.setText("加入圈子请求");
		m_editMsg.setHint("填写申请理由");
		m_btnCancel.setText(R.string.im_popup_resend_cancel);
		m_btnAction.setText(R.string.im_popup_clear_history_confirm);
	}

	@Override
	protected void onActionClick()
	{
		if(m_editMsg.getText().toString().trim().length() == 0){
			ToastUtil.show("请填写申请消息");
			return;
		}
		ProgressBarUtil.showProgress(m_context);


		RetrofitFactory.getRetrofit().create(JoinCircleApi.class)
				.joinCircle(mCircleId, AccountHelper.getUidInt(), m_editMsg.getText().toString())
				.compose(RxUtil.dataNullResult())
				.compose(RxUtil.<BaseImResponse<Object>>rxSchedulerHelper())
				.compose(((RxAppCompatActivity)m_context).<BaseImResponse<Object>>bindToLifecycle())
				.subscribe(new CommonSubscriber<BaseImResponse<Object>>(m_context) {
					@Override
					public void onNext(BaseImResponse<Object> o) {
							String message = "加圈申请已发送！";
							ToastUtil.show(message);
					}

					@Override
					public void onComplete() {
						super.onComplete();
					}
				});
		dismissDialog();
	}

	public void show()
	{
		showDialog();
	}

}
